<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="单据编号" prop="refundcode">
      <el-input v-model="dataForm.refundcode" disabled="disabled" ></el-input>
    </el-form-item>
    <el-form-item label="用户昵称" prop="nickname">
      <el-input v-model="dataForm.nickname" disabled="disabled" ></el-input>
    </el-form-item>
    <el-form-item label="取消时间" prop="refundtime">
      <el-input v-model="dataForm.refundtime" disabled="disabled" ></el-input>
    </el-form-item>
    <el-form-item label="取消理由" prop="refundreason">
      <el-input v-model="dataForm.refundreason" disabled="disabled" ></el-input>
    </el-form-item>
<!--    <el-form-item label="审核状态" prop="status">
      <el-input v-model="dataForm.status"></el-input>
    </el-form-item>-->
    <el-form-item label="源单据号" prop="receiptcode">
      <el-input v-model="dataForm.receiptcode" disabled="disabled" ></el-input>
    </el-form-item>
    <el-form-item label="图片" prop="imgurl"  >
      <div class="feedback-back">
        <div class="feedback-back-img-box">
          <div class="feedback-back-img" @click="icon(item)" v-for="(item,index) in imglist" :key="index">
            <img class="feedback-back-style" :src="item">
          </div>
        </div>
        <div v-if="show" position="center" class="popup" >
          <div class="show-box" @click="close()">
            <img class="feedback-back-ico" :src="bigicon" @click="close()">
          </div>
        </div>
      </div>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <!--<el-button type="primary" @click="dataFormSubmit()">确定</el-button>-->
    </span>
  </el-dialog>
</template>

<style scoped>
  .feedback-back{
    padding: 15px 0;
  }
  .feedback-back-img-box{
    width: 100%;
    overflow: hidden;
    display: block;
  }
  .feedback-back-img{
    width: 20%;
    height: 150px;
    overflow: hidden;
    float: left;
    margin-bottom: 10px;
    padding: 5px;
  }
  .feedback-back-style{
    width: 100%;
    height: 100%;
    border:1px solid #d7d7d7;
    border-radius: 10px;
  }
  .show-box{
    background: rgba(0,0,0,0.5);
    width: 100%;
    height: 100%;
    z-index:99999;
    text-align: center;
    line-height: 60;
  }
  .feedback-back-ico{
    width: 600px;
    margin: 0 auto;
  }
  .popup{
    position: fixed;
    width: 100%;
    bottom: 0;
    z-index: 999999;
    top:0;
    left: 0;
  }
</style>

<script>
  export default {
    data () {
      return {
        visible: false,
        show: false,
        imglist: [],
        bigicon: '',
        dataForm: {
          id: 0,
          refundcode: '',
          nickname: '',
          refundtime: '',
          refundreason: '',
          status: '',
          receiptcode: '',
          imgurl: ''
        },
        dataRule: {
          refundcode: [
            { required: true, message: '退款单编号不能为空', trigger: 'blur' }
          ],
          refundtime: [
            { required: true, message: '退款时间不能为空', trigger: 'blur' }
          ],
          refundreason: [
            { required: true, message: '退款理由不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '审核状态(0:待退款；1:退款成功)不能为空', trigger: 'blur' }
          ],
          receiptid: [
            { required: true, message: '源订单id不能为空', trigger: 'blur' }
          ],
          imgurl: [
            { required: true, message: '图片不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/refundreceipt/refundreceipt/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.refundcode = data.refundreceipt.refundcode
                this.dataForm.refundtime = data.refundreceipt.refundtime
                this.dataForm.refundreason = data.refundreceipt.refundreason
                this.dataForm.status = data.refundreceipt.status
                this.dataForm.receiptid = data.refundreceipt.receiptid
                if (data.refundreceipt.imgurl !== '' && data.refundreceipt.imgurl !== undefined) {
                  this.imglist = data.refundreceipt.imgurl.split(',')
                } else {
                  this.imglist = []
                }
                this.dataForm.nickname = data.refundreceipt.nickname
                this.dataForm.receiptcode = data.refundreceipt.receiptcode
              }
            })
          }
        })
      },
      icon (item) {
        this.show = !this.show
        this.bigicon = item
      },
      close () {
        this.show = !this.show
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/refundreceipt/refundreceipt/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'refundcode': this.dataForm.refundcode,
                'refundtime': this.dataForm.refundtime,
                'refundreason': this.dataForm.refundreason,
                'status': this.dataForm.status,
                'receiptid': this.dataForm.receiptid,
                'imgurl': this.dataForm.imgurl
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1000,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
